package com.one.rope.mvp.web.controller.admin;

import com.one.rope.mvp.web.business.service.IAdminUserService;
import com.one.rope.mvp.web.common.dto.admin.user.AdminUserLoginDTO;
import com.one.rope.mvp.web.common.dto.admin.user.AdminUserLoginVO;
import com.one.rope.mvp.basecore.bean.ResponseObject;
import com.one.rope.mvp.web.common.util.ObjectUtils;
import com.one.rope.mvp.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Weijian.liu
 * @desc 登录认证控制器
 * @date 2020/02/19
 */
@Api(tags = "A1管理后台-用户模块")
@RestController
@Slf4j
public class AdminUserController extends BaseController {

  @Autowired
  IAdminUserService adminUserService;

  @ApiOperation(value = "001用户登录", notes = "管理后台用户登录接口", response = AdminUserLoginVO.class)
  @PostMapping("/admin/login")
  public ResponseObject login(@RequestBody AdminUserLoginDTO requestDTO) {
    ObjectUtils.requestNonEmpty(requestDTO.getAccount(), "登录账号不能为空");
    ObjectUtils.requestNonEmpty(requestDTO.getPassword(), "密码不能为空");
    try {
      return adminUserService.userLogin(requestDTO);
    } catch (Exception e) {
      log.error("/admin/login接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @ApiOperation(value = "002用户退出登录", notes = "用户退出登录接口")
  @GetMapping("/admin/logout")
  public ResponseObject userLogout() {
    try {
      return adminUserService.userLogout();
    } catch (Exception e) {
      log.error("/admin/logout接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

}
